package com.kkb.mybatis.phase1.dao;

import com.kkb.mybatis.phase1.po.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 * author: zsl
 * date: 2019/10/9 16:39
 * Description:
 */
public class UserDapImpl implements UserDao {

    private  SqlSessionFactory sqlSessionFactory;

    //注入 sqlSessionFactory
    public UserDapImpl(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    public User findUserByOne(int id) {
        //sqlsessionFactory工厂类去创建 sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        User user = sqlSession.selectOne("test.findUserByOne", id);
        return user;
    }
}